<?php

namespace App\Http\Controllers\home\lei;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Models\Aptitude;
use App\Http\Models\Business;
use Illuminate\Support\Facades\Input;

class StoreController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        $data = Business::where('id',10)->first();
        $apt = Aptitude::where('ap_business',$data['b_name'])->first();
        return view('home.lei.business.store.index',['data'=>$data,'apt'=>$apt]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = $request->except('_token');
        $bus = Business::find($id);
        $bus->b_phone = $data['b_phone'];
        $bus->b_address = $data['b_address'];
        $bus->b_description = $data['b_description'];
        $bus->b_workTime = $data['startime'].'~~'.$data['endtime'];
        $bus->b_upPrice = $data['b_upPrice'];
        $bus->b_distribution = $data['b_distribution'];
        $bus->b_logo = basename($data['permit']);
        $res = $bus->save();
        if($res){
            return redirect('/home/store');
        }else{
            return back();
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

     public function logo(Request $request)
    {
        $file = Input::file('file_permit');
        if($file->isValid()){
            $entension = $file->getClientOriginalExtension();//上传文件的后缀名
            $newName = date('YmdHis').mt_rand(1000,9999).'.'.$entension;
            $path = $file->move(public_path().'/lei/home/images',$newName);
            $filepath = 'lei/home/images/'.$newName;
            return  $filepath;
        }
    }
}
